
Partial classes allow us to split a class into two or more files. All these parts are then combined into a single class, when the application is compiled. The partial keyword can also be used to split a struct or interface over two or more files. Given bellow the example code and explain the code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using testForClass1;
namespace testFor
{
public partial class Employee
{
public string _firstName { get; set; }
public string _lastName { get; set; }
}
public partial class Employee
{
public string setName(string getFirstName, string getLastName)
{
_firstName = getFirstName;
_lastName = getLastName;
return _firstName + " " + _lastName;
}
}
public class Program
{
static void Main(string[] args)
{
Employee obj = new Employee();
string myName = obj.setName("Farhan Sakib", "Jesy");
Console.WriteLine("My full name is : " + myName);
Console.Read();
}
}
}
In this two Employee partial class. First declare property into one employee class and then initialize the value another Employee partial class and return the value. Now we create a object of Employee and access booth member of classes. Now print the value in to Main method. Partial class work combined two or more classes.